import DetailView from "@/views/DetailView.vue";
import HomeView from "@/views/HomeView.vue";
import LoginView from "@/views/LoginView.vue";
import NotFoundView from "@/views/NotFoundView.vue";
import SearchView from "@/views/SearchView.vue";
import { createRouter, createWebHashHistory,createWebHistory } from "vue-router";

// 创建路由实例对象
const router = createRouter({
    // history:createWebHashHistory(),// 以#为路由做导航
    history:createWebHistory(),// 以#为路由做导航
    routes:[
        // 如果访问的是 localhost:5173/#/ => localhost:5173/#/login
        {
            path:'/',
            redirect:'/login'
        },
        {
            name:'login',
            path:'/login',
            component:()=>import("@/views/LoginView.vue") //懒加载
        },
        {
            name:'home',
            path:'/home/:id?',
            component:()=>import("@/views/HomeView.vue") //懒加载
        },
        {
            path:'/search',
            component:()=>import("@/views/SearchView.vue") //懒加载
        },
        {
            path:'/detail/:name/:a',
            component:()=>import("@/views/DetailView.vue") //懒加载
        },
        {
            path: '/counter',
            component: () => import("@/views/CounterView.vue")
        },
        {
            path: '/anothercounter',
            component: () => import("@/views/AnotherCounter.vue")
        },   
        {
            path:'/:pathMatch(.*)*',
            component:NotFoundView
        }
    ]// 路径 => 组件 router_map.json
})
export default router